class MusicIcon extends egret.DisplayObjectContainer
{
	public closeImg:egret.Bitmap;
    public onImg:egret.Bitmap;
	public isOn:boolean=true;

	public constructor() 
	{
		super();

		this.closeImg=new egret.Bitmap(RES.getRes("musicClose_png"));
		this.closeImg.smoothing=true;
		this.closeImg.x=-this.closeImg.width/2;
		this.closeImg.y=-this.closeImg.height/2;
		this.addChild(this.closeImg);
		this.closeImg.visible=false;
        
		this.onImg=new egret.Bitmap(RES.getRes("musicOn_png"));
		this.onImg.smoothing=true;
		this.onImg.x=-this.onImg.width/2;
		this.onImg.y=-this.onImg.height/2;
		this.addChild(this.onImg);

        this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.touchTapHandle,this);
		this.addEventListener(egret.Event.ENTER_FRAME,this.enterHandle,this);
		this.touchEnabled=true;
	}

	private touchTapHandle(e:egret.TouchEvent):void
	{
        if(this.isOn) this.pauseMusic();
		else this.playMusic();
	}

	private enterHandle(e:egret.Event):void
	{
		if(!this.isOn) return;
        this.rotation+=1;
	}

	public playMusic():void
	{
		if(this.isOn) return;
        this.isOn=true;
		this.closeImg.visible=false;
		this.onImg.visible=true;
		if(window['PlayMusic'])
		{
            window['PlayMusic']();
        }
	}

	public pauseMusic():void
	{
        if(!this.isOn) return;
        this.isOn=false;
		this.closeImg.visible=true;
		this.onImg.visible=false;
		if(window['StopMusic'])
		{
            window['StopMusic']();
        }
	}
}